﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;

namespace ExpressManagement.Areas.BackSys.ServiceTools
{
    public class TestAuthorizationPolicyProvider : DefaultAuthorizationPolicyProvider, IAuthorizationPolicyProvider
    {


        public TestAuthorizationPolicyProvider(IOptions<AuthorizationOptions> options) : base(options) { }

        public new Task GetDefaultPolicyAsync()
        {
            return base.GetDefaultPolicyAsync();
        }

        public new Task GetFallbackPolicyAsync()
        {
            return base.GetFallbackPolicyAsync();
        }


        public new Task GetPolicyAsync(string policyName)
        {
            if (policyName.StartsWith(UserPermission.User))
            {
                var policy = new AuthorizationPolicyBuilder("Bearer");
                policy.AddRequirements(new PermissionAuthorizationRequirement(policyName));
                return Task.FromResult(policy.Build());
            }
            return base.GetPolicyAsync(policyName);
        }
    }




}
